package com.ebeitech.doorapp.domain.dao;

import android.content.ContentValues;

import com.ebeitech.doorapp.db.CommonDBHelper;
import com.ebeitech.doorapp.db.DBChangeInterface;
import com.ebeitech.doorapp.db.dao.BaseDBDaoImpl;
import com.ebeitech.doorapp.domain.User;

/**
 * Created by alice on 2017/10/24.
 */
public class UserDao extends BaseDBDaoImpl<User> implements DBChangeInterface {

	private static UserDao userDao;

	public static UserDao getInstance() {

		if(userDao == null || userDao.dbHelper == null){
			userDao = new UserDao();
		}
		return userDao;
	}

	public UserDao() {
		super(CommonDBHelper.getDBHelper(), User.class);
		CommonDBHelper.addToDaoManager(this);
	}

	public User getUserByAccount(String userAccount){
		return query(null, "userAccount=?", new String[]{userAccount});
	}

	public void setUserLogout(String userAccount){
		ContentValues contentValues = new ContentValues();
		contentValues.put("loginStatus","0");
		update(contentValues,"userAccount=?",new String[]{userAccount});
	}

	@Override
	public void DBChange() {
		userDao = null;
	}
}
